<template>
	<view class="content poRel">
		<view class="wid100 dis disAl bacFFF" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);height: 107rpx;">
			<view class="wid90 mar dis disAl disJuC borRad40 hei60"style="background: #E5E5E5;">
				<view class="dis disJuC" style="width: 13%;">
					<uni-icons type="search" size="25rpx" color="#AFB6B1"></uni-icons>
				</view>
				<input class="wid85" v-model="sousuo" @input="sousuoInput" 
					placeholder="请输入项目名称" placeholder-style="color: #AFB6B1;"/>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 107rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<view style="height: 1rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid90 mar bacFFF mar-top20 borRad10" style="padding: 20rpx 0;">
					<view class="wid90 mar dis " @click.stop="tiaozhuan('/pages/serve/serve?id='+item.id)">
						<view style="width: 25%;height: 142rpx;">
							<image :src="item.cover_img" class="hei100 borRad10" style="width: 142rpx;"></image>
						</view>
						<view style="width: 75%;">
							<view class="dis disAl disJuB">
								<view class="foSi30 fowe600">{{item.name}}</view>
								<view class="foSi20" style="color: #878787;">{{item.all_sales}}人已预约</view>
							</view>
							<view class="foSi20 webkitLineClamp mar-top10" style="color: #878787;">{{item.subtitle}}</view>
							<view class="mar-top20 dis disAl disJuB">
								<view class="dis disAl">
									<view class="foSi15 coFFF tim1" :style="'background-color: '+theme.seco_color+';'">{{item.duration}}分钟</view>
									<view class="mar-left10">
										<view class="foSi20" style="vertical-align: bottom;color: #FF0000;">
											<span>¥</span>
											<span class="fowe600 foSi30">{{item.price}}</span>
											<span class="foSi15 mar-left10 poRel" style="color: #A6A6A6;">
												<span>¥</span>
												<span class="fowe600 foSi20">{{item.orig_price}}</span>
												<view class="wid100 poAbs" style="height: 1rpx;background-color: #A6A6A6;top: 40%;left: 0;"></view>
											</span>
										</view>
									</view>
								</view>
								<view class="dis disAl disJuC foSi22 coFFF butt2" :style="'background-color: '+theme.main_color+';'"
									@click.stop="tiaozhuan('/pages/serve/technicianSelective?id='+item.id)">选择技师</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<view style="height: 150rpx;"></view>
		</scroll-view>
		<view class="poFix wid100 dis disAl disJuC bacFFF" style="height: 124rpx;border-top: 1rpx solid #878787;bottom: 0;">
			<view class="wid90 borRad40 dis disAl disJuC coFFF foSi35" @click="fanhui()"
				style="height: 85rpx;" :style="'background-color: '+theme.main_color+';'">返回上页</view>
		</view>
	</view>
</template>

<script>
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj
		},
		data() {
			return {
				url: this.global.url,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				id: '',
				list: [],
				theme: null
			}
		},
		onLoad(option) {
			this.id = option.id
			this.theme = uni.getStorageSync('theme')
			this.getList()
		},
		methods: {
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					that.page = 1
					that.getList()
					console.log(that.sousuo)
				}, 1000)
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/service/lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id //自定义请求头信息
					},
					data: {
						sort: 0,
						page: that.page,
						keywords: that.sousuo
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			fanhui(){
				uni.navigateBack(1)
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content{
		background-color: #F3F1F1;
	}
	.tim1{
		padding: 10rpx;
		border-radius: 5rpx;
	}
	.butt2{
		width: 125rpx;
		height: 50rpx;
		border-radius: 10rpx;
	}
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
</style>
